package org.applesline.desensitize.handle.impl;

import org.applesline.desensitize.constants.DesensitizeType;
import org.applesline.desensitize.handle.DesensitizeAdapter;
import org.springframework.stereotype.Component;

/**
 * @author liuyaping
 * @date 2022/1/13
 */
@Component
public class EmailHandler extends DesensitizeAdapter {

    @Override
    public String doMask(String email) {
        if (isBlank(email)) {
            return "";
        } else {
            int index = indexOf(email, 64);
            return index <= 1 ? hide(email, 0, index) : hide(email, index <= 3 ? 1 : 3, index);
        }
    }

    @Override
    public DesensitizeType getFieldType() {
        return DesensitizeType.EMAIL;
    }
}
